// 创建一个防抖函数
function debounce(func, wait) {
    let timeout;
    return function(...args) {
      const context = this;
      if (timeout) clearTimeout(timeout);
      timeout = setTimeout(() => {
        func.apply(context, args);
      }, wait);
    };
  }
  
  // 创建防抖指令
  const debounceClickDirective = {
    mounted(el, binding) {
      // 获取绑定的值，即要执行的函数
      const func = binding.value;
      // 获取等待时间，默认为200毫秒
      const wait = binding.arg || 200;
      // 替换原事件监听函数为防抖函数
      el.addEventListener('click', debounce(func, wait));
    },
    unmounted(el, binding) {
      // 组件卸载时移除事件监听
      const func = binding.value;
      const wait = binding.arg
      el.removeEventListener('click', debounce(func, wait));
    }
  };
  export default debounceClickDirective